package com.lam.mall.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import com.lam.common.validate.ValidateUtil;
import com.lam.common.validate.model.ValidOperType;
import com.lam.mall.common.constant.MallConstant;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lam.framework.operLog.annotation.Log;
import com.lam.common.components.dict.annotation.DictAutoTransfer;
import com.lam.framework.annotation.ParamInject;
import com.lam.common.base.controller.BaseController;
import com.lam.common.base.domain.Result;
import com.lam.framework.operLog.enums.BusinessType;
import com.lam.mall.entity.ShopDetail;
import com.lam.mall.param.ShopDetailParam;
import com.lam.mall.service.ShopDetailService;
import org.springframework.validation.annotation.Validated;
import com.lam.common.utils.StringUtils;
import com.lam.common.validate.group.Update;
import com.lam.common.validate.group.Add;

/**
 * 店铺管理Controller
 * 
 * @author admin
 * @date 2023-04-27
 */
@Log(title = "店铺管理")
@ParamInject
@RestController
@RequestMapping("/${adminPath}/mall/shopDetail")
public class ShopDetailController extends BaseController {

    @Autowired
    private ShopDetailService shopDetailService;

    /**
     * 查询店铺管理列表
     */
    @Log(oper="分页查询")
    @DictAutoTransfer
    @PreAuthorize("@ss.hasPm('mall:shopDetail:list')")
    @GetMapping("/list")
    public Result list(ShopDetailParam param) {
    
        startPage();
        List<ShopDetail> list = shopDetailService.selectList(param);
        return Result.ok(getTableData(list));
    }

    /**
     * 获取店铺管理详细信息
     */
    @DictAutoTransfer
    @Log(oper="根据ID查询")
    @PreAuthorize("@ss.hasPm('mall:shopDetail:query')")
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable("id") String id) {
    
        return Result.ok(shopDetailService.selectById(id));
    }

    /**
     * 新增店铺管理
     */
    @PreAuthorize("@ss.hasPm('mall:shopDetail:add')")
    @Log(businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@Validated(Add.class) @RequestBody ShopDetail shopDetail) {
    
        if(StringUtils.isNotBlank(shopDetail.getShopName())) {
            ValidateUtil.validUnique(shopDetail, ValidOperType.ADD, MallConstant.UNIQUE_SHOP_DETAIL_SHOP_NAME, "店铺名称已存在！");
        }
        return toAjax(shopDetailService.insert(shopDetail));
    }

    /**
     * 修改店铺管理
     */
    @PreAuthorize("@ss.hasPm('mall:shopDetail:edit')")
    @Log(businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@Validated(Update.class) @RequestBody ShopDetail shopDetail) {
    
    	if(StringUtils.isNotBlank(shopDetail.getShopName())) {
            ValidateUtil.validUnique(shopDetail, ValidOperType.UPDATE, MallConstant.UNIQUE_SHOP_DETAIL_SHOP_NAME, "店铺名称已存在！");
        }
        return toAjax(shopDetailService.update(shopDetail));
    }

    /**
     * 删除店铺管理
     */
    @PreAuthorize("@ss.hasPm('mall:shopDetail:remove')")
    @Log(businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public Result remove(@PathVariable String id) {
    
        return toAjax(shopDetailService.deleteById(id));
    }

}
